package com.example.designpatterns.model.observer;

import org.apache.logging.log4j.message.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yanyun zhu
 * @version 1.0
 * @date 2022/1/4 9:08
 */
public class ConcreteSubject implements Subject {
    private List<Observer> observers = new ArrayList();

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers(Message message) {
        for (Observer observer : observers) {
            observer.update(message);
        }
    }
}
